using System;

namespace ConsoleApp {
	class Class1 {
		[STAThread]
		static void Main(string[] args) {
			Test();
		}
		protected static MSNConnector.Connection conn = new MSNConnector.Connection();


		public static void Test() {

            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.ConsoleTraceListener());            
			System.Collections.Specialized.NameValueCollection settings = System.Configuration.ConfigurationSettings.AppSettings;
			string timeout = settings["ConnectionRetryTimeout"];
			if(timeout!=null && timeout.Trim()!="") conn.ConnectionRetryTimeout = Convert.ToInt64( timeout );

            conn.OnLogin += new MSNConnector.Connection.LoginEventHandler(conn_OnLogin);
            conn.StartMSN(settings["MSNEmail"], settings["MSNPassword"]);

            string input = "";
            while (input != "exit")
            {
                if(input=="msnname") System.Diagnostics.Trace.WriteLine( conn.GetFullScreenName());
                if (input == "msnstatus") System.Diagnostics.Trace.WriteLine(conn.GetStatus());
                if (input.StartsWith("msnchat:"))
                {
                    input = input.Substring("msnchat:".Length);
                    string email = input.Substring(0, input.IndexOf("|"));
                    string msg = input.Substring(input.IndexOf("|")+1);
                    conn.Chat(email, msg);
                }
                input = Console.ReadLine();
            }
			
		}
		public static bool LoggedIn = false;

		private static void conn_OnLogin(object sender, EventArgs e) {
            //LoggedIn=true;
            //System.Random rnd = new Random();
            //string ScreenNames=System.Configuration.ConfigurationSettings.AppSettings["ScreenNames"];
            //string sn="Anika";			
            //if(ScreenNames!=null && ScreenNames.Trim()!="") {
            //    string[] names = ScreenNames.Split(',');
            //    sn = names[rnd.Next(names.Length-1)];			
            //}
			
            //conn.SetScreenName(sn);
			//System.Threading.Thread.Sleep(60000);
			//conn.SetDisplayPicture(@"c:\metal.jpg");
		}
	}
}
